<?php

require_once('load.php');
$smarty->assign("s1","user");

if(LOGGED == false)header('Location: ./index.php');


if(isset($_GET['action'])){
	switch ($_GET['action']) {
		case 'usunklienta':
			// $_get['id'] - identyfikator klienta 
			//
			if($sql->query("delete from `uzytkownicy` where `id`='".$_GET['id']."'")){
				header('Location: ./users.php?action=success');
			}else{
				header('Location: ./users.php?action=failed');
			}	
			break;
		case 'dodajuser':
			if($sql->query("insert into `uzytkownicy` (`prawa`, `login`, `haslo`, `imie`, `nazwisko`, `mail`) values ('1', '".$_POST['login']."', '".md5($_POST['passa'])."', '".$_POST['imie']."', '".$_POST['nazwisko']."', '".$_POST['mail']."')")){
				header('Location: ./users.php?action=success');
			}else{
				header('Location: ./users.php?action=failed');
			}	
			break;
		case 'nadajprawa':
		
			if($sql->query("update `uzytkownicy` set `prawa`='".$_POST['newgrupa']."' where `id`='".$_GET['id']."'")){
				header('Location: ./users.php?action=success');
			}else{
				header('Location: ./users.php?action=failed');
			}
			break;	
		case 'dodajadmina':
			if($sql->query("insert into `admin` (`admin_login`, `admin_pass`, `admin_prawa`, `admin_mail`) values ('".$_POST['login']."', '".$_POST['passa']."', '5', '".$_POST['mail']."')")){
				header('Location: ./users.php?action=success');
			}else{
				header('Location: ./users.php?action=failed');
			}	
			break;	
		case 'failed':
		
			if(isset($_GET['k'])){
				if($_GET['k'] == 'logowanie'){
					$smarty->assign("komunikat","Zły login lub hasło");
				}else{
					$smarty->assign("komunikator","Wstąpił błąd");
				}
			}else{
				$smarty->assign("komunikat","Wstąpil błąd");
			}
			
			break;
		case 'success':
		
			if(isset($_GET['k'])){
				if($_GET['k'] == 'zalogowano'){
					$smarty->assign("komunikat","Zalogowano");
				}else{
					$smarty->assign("komunikator","Pomyslnie zakonczono");
				}
			}else{
				$smarty->assign("komunikat","Pomyslnie zakonczono");
			}
			break;

	}
}
$system->dodaj_js('skrypty.js');
$smarty->display('templates/index.tpl');
?>